using System;
using DM.DAO;
using DM.Entity;

namespace DM.Web.Admin
{
    public partial class SiteAdmin : System.Web.UI.MasterPage
    {
        public String appPath;

        protected void Page_Load(object sender, EventArgs e)
        {

            NsdDAO nsdService = new NsdDAO();
            NSD nsd = new NSD();
            appPath = Common.ApplicationPath;
            try
            {
                nsd = (NSD)Session["nsd"];
                if (nsd == null)
                {
                    try
                    {
                        if (Request.Cookies["userInfo"] != null)
                        {
                            Request.Cookies["userInfo"].Expires = DateTime.Now.AddMinutes(60);
                            Response.Cookies.Add(Request.Cookies["userInfo"]);
                            string userName = Request.Cookies["userInfo"]["userName"];
                            nsd = nsdService.Get(userName);
                            Session["nsd"] = nsd;
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.Show(ex.Message, Request.UrlReferrer.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Common.Show(ex.Message, Request.UrlReferrer.ToString());
            }
            if (!IsPostBack)
            {
                nsd = (NSD)Session["nsd"];
                if (nsd == null || nsd.Manhomnsd.ToString() != "2")
                {
                    Response.Redirect(appPath + "Admin/Login.aspx");
                }
                if (nsd.Hoten != null)
                {
                    LabelUserName.Text = nsd.Hoten;
                }
                //if (Request.QueryString["keyword"] != null && Request.QueryString["keyword"] != "")
                //{
                //    TextBoxSearch.Text = Request.QueryString["keyword"].ToString();
                //}
            }

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect("TimKiemAdmin.aspx?key="+txtSearch.Text);
        }
    }
}
